<?php
if(isset($_GET["fname"]))
{
	$myfile = './data/store/' . $_GET["fname"];
//	echo "AMEN ";
	if(!file_exists($myfile))
	{	
//		echo "Here ";
		$execstring = "./nehovah " . $_GET["word0"]  . " " . $_GET["word1"];
//		echo "Here ";
//		echo "Executing (" ;
//		echo $execstring;
//		echo ")\n";
		$fh = fopen($myfile, 'w') or die("can't open file");
		chmod($myfile, 0777) or die("can't set permissions");
		exec($execstring, $output);
		$count = count($output);
		for($i =0; $i < $count; $i++)
		{
//			echo $output[$i] . "\n";
			fwrite($fh, $output[$i] . "\n") or die("cant write to file");
		}
		fclose($fh); 
	}
//	echo "Done!";
	//sort file
	$execstring = "./sorter " . $myfile . " " . $_GET["s0"] . " " . $_GET["s1"] . " " . $_GET["s2"] . " " . $_GET["s3"];
	//echo $execstring;
	system($execstring);

} else
{
	echo "bad query";
}
?>